package com.ayoka.ui.assignment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.ayoka.R;
import com.ayoka.base.BaseActivity;
import com.ayoka.databinding.ActivityCourseAssignmentDetailBinding;
import com.jcp.baselibrary.model.ToolBarOptions;

import com.ayoka.bean.CourseAssignmentBean;
import com.ayoka.mvp.CourseAssignmentMVP.CourseAssignmentPresenter;
import com.ayoka.mvp.CourseAssignmentMVP.ICourseAssignmentView;

/**
 * @author jcp
 * @ClassName: TopicListActivity
 * @Description:
 * @date 2018-12-28 下午4:21:18
 */
public class CourseAssignmentDetailActivity extends BaseActivity<ActivityCourseAssignmentDetailBinding, CourseAssignmentPresenter> implements ICourseAssignmentView {
    private static int OPERATE_ADD_RECORD = 0x001;
    private static int OPERATE_ADD_NOTE = 0x002;

    public static void start(Activity activity, CourseAssignmentBean courseAssignmentBean) {
        Intent intent = new Intent(activity, CourseAssignmentDetailActivity.class);
        intent.putExtra("CourseAssignmentBean", courseAssignmentBean);
        activity.startActivityForResult(intent, REQUEST_CODE_FOR_RESULT);
    }

    private CourseAssignmentBean courseAssignmentBean;
    private int courseAssignmentId;
    private int courseId;
    private int assignmentType;

    private Fragment currentFragment;

    // 操作类型
    private int operateType;
    // 添加记录的Id
    private int recordId;

    @Override
    protected void configIntentValue() {
        courseAssignmentBean = (CourseAssignmentBean) getIntent().getSerializableExtra("CourseAssignmentBean");
        courseAssignmentId = courseAssignmentBean.ID;
        courseId = courseAssignmentBean.CourseID;
        assignmentType = courseAssignmentBean.AssignmentType;
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_course_assignment_detail;
    }

    @Override
    protected void initViews() {
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        ToolBarOptions options = new ToolBarOptions("作业");
        setCustomToolBar(mDataBinding.customToolbar.toolbar, options);

        configFragment();
    }


    @Override
    protected CourseAssignmentPresenter getPresenter() {
        return null;
    }

    private void configFragment() {
        if (assignmentType == CourseAssignmentBean.ASSIGNMENT_APPRECIATE) {
            currentFragment = CourseAssignmentAppreciateFragment.newInstance(courseAssignmentBean);
        } else if (assignmentType == CourseAssignmentBean.ASSIGNMENT_TRAINING) {
            currentFragment = CourseAssignmentTrainingFragment.newInstance(courseAssignmentBean);
        } else if (assignmentType == CourseAssignmentBean.ASSIGNMENT_ADMIXTURE) {
            currentFragment = CourseAssignmentAdmixtureFragment.newInstance(courseAssignmentBean);
        } else if (assignmentType == CourseAssignmentBean.ASSIGNMENT_VIDEO) {
            currentFragment = CourseAssignmentVideoFragment.newInstance(courseAssignmentBean);
        }
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.frameLayout, currentFragment).commitAllowingStateLoss();
    }

    public void submitCourseAssignment(String requestParam) {
        if (assignmentType == CourseAssignmentBean.ASSIGNMENT_TRAINING) {
            operateType = OPERATE_ADD_RECORD;
        }
        mPresenter.submitCourseAssignment(assignmentType, requestParam);
    }

    @Override
    public void configCourseAssignmentDetailData(CourseAssignmentBean result) {

    }
}
